<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge" >
  <title>iOS网络--『文件下载、断点下载』的实现（三）：AFNetworking | Grx Blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="目录
AFNetworking下载简介AFNetworking下载相关2.1 AFNetworking（文件下载）2.2 AFNetworking（断点下载 | 支持离线）关于『文件下载、断点下载』所有实现的Demo地址：Demo地址
iOS网络–『文件下载、断点下载』的实现相关文章：">
<meta property="og:type" content="article">
<meta property="og:title" content="iOS网络--『文件下载、断点下载』的实现（三）：AFNetworking">
<meta property="og:url" content="http://yoursite.com/2017/02/14/iOS网络-『文件下载、断点下载』的实现（三）：AFNetworking/index.html">
<meta property="og:site_name" content="Grx Blog">
<meta property="og:description" content="目录
AFNetworking下载简介AFNetworking下载相关2.1 AFNetworking（文件下载）2.2 AFNetworking（断点下载 | 支持离线）关于『文件下载、断点下载』所有实现的Demo地址：Demo地址
iOS网络–『文件下载、断点下载』的实现相关文章：">
<meta property="og:updated_time" content="2017-02-14T02:46:26.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="iOS网络--『文件下载、断点下载』的实现（三）：AFNetworking">
<meta name="twitter:description" content="目录
AFNetworking下载简介AFNetworking下载相关2.1 AFNetworking（文件下载）2.2 AFNetworking（断点下载 | 支持离线）关于『文件下载、断点下载』所有实现的Demo地址：Demo地址
iOS网络–『文件下载、断点下载』的实现相关文章：">
  
    <link rel="alternative" href="/atom.xml" title="Grx Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link rel="stylesheet" href="/css/style.css">
</head>

<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
	<header id="header" class="inner">
		<a href="/" class="profilepic">
			
			<img lazy-src="/img/rufei.jpg" class="js-avatar">
			
		</a>

		<hgroup>
		  <h1 class="header-author"><a href="/">Grx</a></h1>
		</hgroup>

		
		<p class="header-subtitle">自我管理，知识管理，时间管理，阅读，语音写作，思维导图</p>
		

		
			<div class="switch-btn">
				<div class="icon">
					<div class="icon-ctn">
						<div class="icon-wrap icon-house" data-idx="0">
							<div class="birdhouse"></div>
							<div class="birdhouse_holes"></div>
						</div>
						<div class="icon-wrap icon-ribbon hide" data-idx="1">
							<div class="ribbon"></div>
						</div>
						
						<div class="icon-wrap icon-link hide" data-idx="2">
							<div class="loopback_l"></div>
							<div class="loopback_r"></div>
						</div>
						
						
						<div class="icon-wrap icon-me hide" data-idx="3">
							<div class="user"></div>
							<div class="shoulder"></div>
						</div>
						
					</div>
					
				</div>
				<div class="tips-box hide">
					<div class="tips-arrow"></div>
					<ul class="tips-inner">
						<li>菜单</li>
						<li>标签</li>
						
						<li>友情链接</li>
						
						
						<li>关于我</li>
						
					</ul>
				</div>
			</div>
		

		<div class="switch-area">
			<div class="switch-wrap">
				<section class="switch-part switch-part1">
					<nav class="header-menu">
						<ul>
						
							<li><a href="/">主页</a></li>
				        
							<li><a href="/tags/life">随笔</a></li>
				        
							<li><a href="/archives">所有文章</a></li>
				        
						</ul>
					</nav>
					<nav class="header-nav">
						<div class="social">
							
								<a class="github" target="_blank" href="https://github.com/ruixiaoguo" title="github">github</a>
					        
								<a class="weibo" target="_blank" href="https://weibo.com/u/3984935859?refer_flag=1005055010_" title="weibo">weibo</a>
					        
								<a class="rss" target="_blank" href="#" title="rss">rss</a>
					        
								<a class="zhihu" target="_blank" href="#" title="zhihu">zhihu</a>
					        
						</div>
					</nav>
				</section>
				
				
				<section class="switch-part switch-part2">
					<div class="widget tagcloud" id="js-tagcloud">
						<a href="/tags/OC/" style="font-size: 10px;">-OC</a> <a href="/tags/Android/" style="font-size: 10px;">Android</a> <a href="/tags/Apple-Watch/" style="font-size: 10px;">Apple Watch</a> <a href="/tags/Flutter/" style="font-size: 13.33px;">Flutter</a> <a href="/tags/Life/" style="font-size: 10px;">Life</a> <a href="/tags/Lottie/" style="font-size: 10px;">Lottie</a> <a href="/tags/MMKV/" style="font-size: 10px;">MMKV</a> <a href="/tags/MonkeyKing/" style="font-size: 10px;">MonkeyKing</a> <a href="/tags/OC/" style="font-size: 20px;">OC</a> <a href="/tags/RAC/" style="font-size: 11.67px;">RAC</a> <a href="/tags/Swift/" style="font-size: 15px;">Swift</a> <a href="/tags/WKWebView/" style="font-size: 10px;">WKWebView</a> <a href="/tags/WebView/" style="font-size: 10px;">WebView</a> <a href="/tags/Xcode/" style="font-size: 18.33px;">Xcode</a> <a href="/tags/appledoc/" style="font-size: 10px;">appledoc</a> <a href="/tags/hexo/" style="font-size: 11.67px;">hexo</a> <a href="/tags/ios/" style="font-size: 10px;">ios</a> <a href="/tags/life/" style="font-size: 16.67px;">life</a> <a href="/tags/xcode/" style="font-size: 10px;">xcode</a>
					</div>
				</section>
				
				
				
				<section class="switch-part switch-part3">
					<div id="js-friends">
					
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://blog.devtang.com">唐巧的博客</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://beyondvincent.com">破船之家</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://limboy.me">无网不剩</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://msching.github.io">码农人生</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://yulingtianxia.com">玉令天下</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://blog.leichunfeng.com">雷纯锋的技术博客</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://jax.cnblogs.com">包建强</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://blog.cnbang.net">bang</a>
			        
			        </div>
				</section>
				

				
				
				<section class="switch-part switch-part4">
				
					<div id="js-aboutme">知识管理，时间管理，自我管理，阅读，语音写作，思维导图，Wiz，TimeMeter</div>
				</section>
				
			</div>
		</div>
	</header>				
</div>

    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
  	<div class="overlay">
  		<div class="slider-trigger"></div>
  		<h1 class="header-author js-mobile-header hide">Grx</h1>
  	</div>
	<div class="intrude-less">
		<header id="header" class="inner">
			<div class="profilepic">
			
				<img lazy-src="/img/rufei.jpg" class="js-avatar">
			
			</div>
			<hgroup>
			  <h1 class="header-author">Grx</h1>
			</hgroup>
			
			<p class="header-subtitle">自我管理，知识管理，时间管理，阅读，语音写作，思维导图</p>
			
			<nav class="header-menu">
				<ul>
				
					<li><a href="/">主页</a></li>
		        
					<li><a href="/tags/life">随笔</a></li>
		        
					<li><a href="/archives">所有文章</a></li>
		        
		        <div class="clearfix"></div>
				</ul>
			</nav>
			<nav class="header-nav">
				<div class="social">
					
						<a class="github" target="_blank" href="https://github.com/ruixiaoguo" title="github">github</a>
			        
						<a class="weibo" target="_blank" href="https://weibo.com/u/3984935859?refer_flag=1005055010_" title="weibo">weibo</a>
			        
						<a class="rss" target="_blank" href="#" title="rss">rss</a>
			        
						<a class="zhihu" target="_blank" href="#" title="zhihu">zhihu</a>
			        
				</div>
			</nav>
		</header>				
	</div>
</nav>

      <div class="body-wrap"><article id="post-iOS网络-『文件下载、断点下载』的实现（三）：AFNetworking" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2017/02/14/iOS网络-『文件下载、断点下载』的实现（三）：AFNetworking/" class="article-date">
  	<time datetime="2017-02-14T02:32:28.000Z" itemprop="datePublished">2017-02-14</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      iOS网络--『文件下载、断点下载』的实现（三）：AFNetworking
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
	<div class="article-tag tagcloud">
		<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/OC/">OC</a></li></ul>
	</div>

        

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
        <blockquote>
<p>目录</p>
<p>AFNetworking下载简介<br>AFNetworking下载相关<br>2.1 AFNetworking（文件下载）<br>2.2 AFNetworking（断点下载 | 支持离线）<br>关于『文件下载、断点下载』所有实现的Demo地址：<br><a href="https://github.com/lianai911/YSC-DownloadDemo" target="_blank" rel="external">Demo地址</a></p>
<p>iOS网络–『文件下载、断点下载』的实现相关文章：</p>
</blockquote>
<a id="more"></a>
<p><a href="http://www.jianshu.com/p/ce3eaee74bde" target="_blank" rel="external">iOS网络–『文件下载、断点下载』的实现（一）：NSURLConnection</a></p>
<p><a href="http://www.jianshu.com/p/5a07352e9473" target="_blank" rel="external">iOS网络–『文件下载、断点下载』的实现（二）：NSURLSession</a></p>
<p><a href="http://www.jianshu.com/p/01390c7a4957" target="_blank" rel="external">iOS网络–『文件下载、断点下载』的实现（三）：AFNetworking</a></p>
<ol>
<li>AFNetworking下载简介</li>
</ol>
<p>这里只讲解AFNetworking下载文件相关知识。对于第三方框架的导入在这里不做讲解，如果有问题可以上AFNetworking的GitHub上了解。—&gt; <a href="https://github.com/AFNetworking/AFNetworking" target="_blank" rel="external">AFNetworking官方地址</a></p>
<ol>
<li>AFNetworking下载相关</li>
</ol>
<p>2.1 AFNetworking（文件下载）</p>
<p>AAFNetworking（文件下载）效果.gif<br>AFNetworking实现文件下载总共四步：</p>
<p>创建会话管理者<br>创建下载路径和请求对象<br>创建下载任务<br>启动下载任务<br>具体实现代码如下：</p>
<pre><code>  NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  // 1. 创建会话管理者
  AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

  // 2. 创建下载路径和请求对象
  NSURL *URL = [NSURL URLWithString:@&quot;http://dldir1.qq.com/qqfile/QQforMac/QQ_V5.4.0.dmg&quot;];
  NSURLRequest *request = [NSURLRequest requestWithURL:URL];

 // 3.创建下载任务
 /**
  * 第一个参数 - request：请求对象
  * 第二个参数 - progress：下载进度block
  *      其中： downloadProgress.completedUnitCount：已经完成的大小
  *            downloadProgress.totalUnitCount：文件的总大小
  * 第三个参数 - destination：自动完成文件剪切操作
  *      其中： 返回值:该文件应该被剪切到哪里
  *            targetPath：临时路径 tmp NSURL
  *            response：响应头
  * 第四个参数 - completionHandler：下载完成回调
  *      其中： filePath：真实路径 == 第三个参数的返回值
  *            error:错误信息
  */
  NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress *downloadProgress) {

// 下载进度
self.progressView.progress = 1.0 * downloadProgress.completedUnitCount / downloadProgress.totalUnitCount;
self.progressLabel.text = [NSString stringWithFormat:@&quot;当前下载进度:%.2f%%&quot;,100.0 * downloadProgress.completedUnitCount / downloadProgress.totalUnitCount];

} destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {

NSURL *path = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
return [path URLByAppendingPathComponent:@&quot;QQ_V5.4.0.dmg&quot;]; 

} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {        
NSLog(@&quot;File downloaded to: %@&quot;, filePath);
 }];

// 4. 开启下载任务
[downloadTask resume];
2.2 AFNetworking（断点下载 | 支持离线）
</code></pre><p>AFNetworking（断点下载 | 支持离线）下载效果.gif<br>AFNetworking3.0是基于NSURLSession的。所以实现原理和NSURLSession差不多。可参考NSURLConnection实现断点下载的方法。<br>相关文章链接：iOS网络 - 『文件下载、断点下载』的实现（二）：NSURLSession。<br>这里使用了NSURLSessionDataTask，以便实现『离线断点下载』。</p>
<p>具体实现步骤如下：</p>
<pre><code> 定义下载文件需要用到的类，这里不需要实现代理
 @interface ViewController ()

  /** 下载进度条 */
  @property (weak, nonatomic) IBOutlet UIProgressView *progressView;
  /** 下载进度条Label */
  @property (weak, nonatomic) IBOutlet UILabel *progressLabel;

  /** AFNetworking断点下载（支持离线）需用到的属性 **********/
  /** 文件的总长度 */
  @property (nonatomic, assign) NSInteger fileLength;
  /** 当前下载长度 */
  @property (nonatomic, assign) NSInteger currentLength;
  /** 文件句柄对象 */
  @property (nonatomic, strong) NSFileHandle *fileHandle;

  /** 下载任务 */
  @property (nonatomic, strong) NSURLSessionDataTask *downloadTask;
  /* AFURLSessionManager */
  @property (nonatomic, strong) AFURLSessionManager *manager;

  @end
  添加全局NSURLSessionDataTask、AFURLSessionManager懒加载代码。这里我把实现『离线断点下载』的代码都放这里了。
  /**
   * manager的懒加载
   */
 - (AFURLSessionManager *)manager {
if (!_manager) {
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    // 1. 创建会话管理者
    _manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
}
return _manager;
}

/**
 * downloadTask的懒加载
 */
- (NSURLSessionDataTask *)downloadTask {
if (!_downloadTask) {
    // 创建下载URL
    NSURL *url = [NSURL URLWithString:@&quot;http://dldir1.qq.com/qqfile/QQforMac/QQ_V5.4.0.dmg&quot;];

    // 2.创建request请求
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    // 设置HTTP请求头中的Range
    NSString *range = [NSString stringWithFormat:@&quot;bytes=%zd-&quot;, self.currentLength];
    [request setValue:range forHTTPHeaderField:@&quot;Range&quot;];

    __weak typeof(self) weakSelf = self;
    _downloadTask = [self.manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
        NSLog(@&quot;dataTaskWithRequest&quot;);

        // 清空长度
        weakSelf.currentLength = 0;
        weakSelf.fileLength = 0;

        // 关闭fileHandle
        [weakSelf.fileHandle closeFile];
        weakSelf.fileHandle = nil;

    }];

    [self.manager setDataTaskDidReceiveResponseBlock:^NSURLSessionResponseDisposition(NSURLSession * _Nonnull session, NSURLSessionDataTask * _Nonnull dataTask, NSURLResponse * _Nonnull response) {
        NSLog(@&quot;NSURLSessionResponseDisposition&quot;);

        // 获得下载文件的总长度：请求下载的文件长度 + 当前已经下载的文件长度
        weakSelf.fileLength = response.expectedContentLength + self.currentLength;

        // 沙盒文件路径
        NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@&quot;QQ_V5.4.0.dmg&quot;];

        NSLog(@&quot;File downloaded to: %@&quot;,path);

        // 创建一个空的文件到沙盒中
        NSFileManager *manager = [NSFileManager defaultManager];

        if (![manager fileExistsAtPath:path]) {
            // 如果没有下载文件的话，就创建一个文件。如果有下载文件的话，则不用重新创建(不然会覆盖掉之前的文件)
            [manager createFileAtPath:path contents:nil attributes:nil];
        }

        // 创建文件句柄
        weakSelf.fileHandle = [NSFileHandle fileHandleForWritingAtPath:path];

        // 允许处理服务器的响应，才会继续接收服务器返回的数据
        return NSURLSessionResponseAllow;
    }];

    [self.manager setDataTaskDidReceiveDataBlock:^(NSURLSession * _Nonnull session, NSURLSessionDataTask * _Nonnull dataTask, NSData * _Nonnull data) {
        NSLog(@&quot;setDataTaskDidReceiveDataBlock&quot;);

        // 指定数据的写入位置 -- 文件内容的最后面
        [weakSelf.fileHandle seekToEndOfFile];

        // 向沙盒写入数据
        [weakSelf.fileHandle writeData:data];

        // 拼接文件总长度
        weakSelf.currentLength += data.length;

        // 获取主线程，不然无法正确显示进度。
        NSOperationQueue* mainQueue = [NSOperationQueue mainQueue];
        [mainQueue addOperationWithBlock:^{
            // 下载进度
            if (weakSelf.fileLength == 0) {
                weakSelf.progressView.progress = 0.0;
                weakSelf.progressLabel.text = [NSString stringWithFormat:@&quot;当前下载进度:00.00%%&quot;];
            } else {
                weakSelf.progressView.progress =  1.0 * weakSelf.currentLength / weakSelf.fileLength;
                weakSelf.progressLabel.text = [NSString stringWithFormat:@&quot;当前下载进度:%.2f%%&quot;,100.0 * weakSelf.currentLength / weakSelf.fileLength];
            }

        }];
    }];
}
return _downloadTask;
}
添加支持断点下载的[开始下载/暂停下载]按钮，并实现相应功能的代码
/**
 * 点击按钮 -- 使用AFNetworking断点下载（支持离线）
 */
- (IBAction)OfflinResumeDownloadBtnClicked:(UIButton *)sender {
// 按钮状态取反
sender.selected = !sender.isSelected;

if (sender.selected) { // [开始下载/继续下载]
    // 沙盒文件路径
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@&quot;QQ_V5.4.0.dmg&quot;];

    NSInteger currentLength = [self fileLengthForPath:path];
    if (currentLength &gt; 0) {  // [继续下载]
        self.currentLength = currentLength;
    }

    [self.downloadTask resume];

} else {
    [self.downloadTask suspend];
    self.downloadTask = nil;
}
}

/**
 * 获取已下载的文件大小
 */
- (NSInteger)fileLengthForPath:(NSString *)path {
NSInteger fileLength = 0;
NSFileManager *fileManager = [[NSFileManager alloc] init]; // default is not thread safe
if ([fileManager fileExistsAtPath:path]) {
    NSError *error = nil;
    NSDictionary *fileDict = [fileManager attributesOfItemAtPath:path error:&amp;error];
    if (!error &amp;&amp; fileDict) {
        fileLength = [fileDict fileSize];
    }
}
return fileLength;
}
</code></pre><p>这样我们用AFNetworking也实现了『离线断点下载』的需求。</p>

      
    </div>
    
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2017/02/24/Xcode8-1如何支持iOS8-0以下版本/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption"><</strong>
      <div class="article-nav-title">
        
          Xcode8.1如何支持iOS8.0以下版本
        
      </div>
    </a>
  
  
    <a href="/2016/06/25/Apple Watch 指南/" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">Apple Watch 指南</div>
      <strong class="article-nav-caption">></strong>
    </a>
  
</nav>

  
</article>


<div class="share_jia">
	<!-- JiaThis Button BEGIN -->
	<div class="jiathis_style">
		<span class="jiathis_txt">Share to: &nbsp; </span>
		<a class="jiathis_button_facebook"></a> 
    <a class="jiathis_button_twitter"></a>
    <a class="jiathis_button_plus"></a> 
    <a class="jiathis_button_tsina"></a>
		<a class="jiathis_button_cqq"></a>
		<a class="jiathis_button_douban"></a>
		<a class="jiathis_button_weixin"></a>
		<a class="jiathis_button_tumblr"></a>
    <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	</div>
	<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=1405949716054953" charset="utf-8"></script>
	<!-- JiaThis Button END -->
</div>






<div class="duoshuo">
	<!-- 多说评论框 start -->
	<div class="ds-thread" data-thread-key="iOS网络-『文件下载、断点下载』的实现（三）：AFNetworking" data-title="iOS网络--『文件下载、断点下载』的实现（三）：AFNetworking" data-url="http://yoursite.com/2017/02/14/iOS网络-『文件下载、断点下载』的实现（三）：AFNetworking/"></div>
	<!-- 多说评论框 end -->
	<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
	<script type="text/javascript">
	var duoshuoQuery = {short_name:"true"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
	<!-- 多说公共JS代码 end -->
</div>




</div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info">
    	<div class="footer-left">
    		&copy; 2019 Grx
    	</div>
      	<div class="footer-right">
      		<a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
      	</div>
    </div>
  </div>
</footer>
    </div>
    
  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">


<script>
	var yiliaConfig = {
		fancybox: true,
		mathjax: true,
		animate: true,
		isHome: false,
		isPost: true,
		isArchive: false,
		isTag: false,
		isCategory: false,
		open_in_new: false
	}
</script>
<script src="http://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script>
<script src="/js/main.js"></script>






<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    }
});

MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';                 
    }       
});
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  </div>
</body>
</html>